﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace HA.Data.DisplayOptions2
{
    [Serializable]
    public class DOGrid3d : EventProperty,IObjectDataHelper, ICloneable
    {
        /// <summary>
        /// 网格选项卡   
        /// </summary>
        public DOGrid3d()
        {
            //this._contourOption = new DOContourOption();

            this._contour = new DOContour();

            this._vector = new DOVector();

        }





        //[field: NonSerialized]
        //public event EventHandler IsShowContourChanged;
        //[field: NonSerialized]
        //public event EventHandler IsShowVectorChanged;



        private bool _isShowContour = true;


        /// <summary>
        /// 是否显示等值线
        /// </summary>
        public bool IsShowContour
        {
            get { return _isShowContour; }
            set
            {
                if (_isShowContour == value)
                {
                    return;
                }
                else
                {
                    _isShowContour = value;
                    this.IsNeedUpdateData = true;
                }
            }
        }


        bool _isShowVector = true;
        /// <summary>
        /// 是否显示向量线
        /// </summary>
        public bool IsShowVector
        {
            get { return _isShowVector; }
            set
            {
                if (_isShowVector == value)
                {
                    return;
                }
                else
                {
                    _isShowVector = value;
                    this.IsNeedUpdateData = true;
                }
            }
        }

       


        //private ContourType contourType = ContourType.LayerContour ;
        ///// <summary>
        ///// 标记是否选择Contour 及类型（GridContour还是LayerContour）
        ///// </summary>
        //public ContourType ContourType
        //{
        //    get { return contourType; }
        //    //set { chooseContour = value; }
        //}


        DOContour _contour;
        /// <summary>
        /// 新的等值线选项部分
        /// </summary>
        public DOContour Contour
        {
            get { return _contour; }

        }


        DOVector _vector ;
        /// <summary>
        /// 向量相关的显示选项
        /// </summary>
        public DOVector Vector
        {
            get { return _vector; }
            //set { _vector = value; }
        }




        public override void SetIsNeedUpdateDataToFalse()
        {
            base.SetIsNeedUpdateDataToFalse();

            this.isNeedUpdateData = false;

            if (this._contour !=null )
            {
                this._contour.SetIsNeedUpdateDataToFalse();
            }
            if (this._vector !=null )
            {
                this._vector.SetIsNeedUpdateDataToFalse();
            }
        }



        #region ICloneable 成员

        public object Clone()
        {

            DOGrid3d obj = (DOGrid3d)this.MemberwiseClone();

            if (this._contour != null)
            {
                obj._contour = (DOContour)this._contour.Clone();
            }
            else 
            {
                obj._contour = null;
            }

            if (this._vector != null)
            {
                obj._vector = (DOVector)this._vector.Clone();
            }
            else 
            {
                obj._vector = null ;            
            }
            
            return obj;


            //throw new NotImplementedException();
        }

        #endregion

        #region IObjectDataHelper 成员
        /// <summary>
        /// 更新副本数据到原始数据数据   判断对应的选项改变，并作出对应的更新动作
        /// </summary>
        /// <param name="obj"></param>
        public void ResetDataAndTriggerEvent(object obj)
        {
            if (obj==null )
            {
                return;
            }

            DOGrid3d grid = (DOGrid3d)obj;

            if (grid.IsDataChanged () ==false )
            {
                return;
            }
       
            try
            {
                #region

                //数据更新不会影响到单独走事件更新的数据(也不包括单独走事件的数据部分的更新)


                List<string> properties = new List<string>();

                if (this._isShowContour != grid.IsShowContour)
                {
                    this._isShowContour = grid._isShowContour;

                    properties.Add(DOGrid3dType .IsShowContour.ToString());
                }

                if (this._isShowVector != grid.IsShowVector)
                {
                    this._isShowVector = grid.IsShowVector;

                    properties.Add(DOGrid3dType.IsShowVector.ToString());
                }




                if (properties.Count > 0)
                {
                    this.AskDisplayOptionChanged(new DisplayOptionsChangedEventArgs(this, DisplayOptionsType.Grid3D, properties));
                }

                #endregion



            }
            catch
            {


            }



            ///等值线的详细设置改变，不通过字段传递



            //throw new NotImplementedException();
        }

        /// <summary>
        /// 
        /// 判断类中所有数据（包括作为其字段的类的实例（对象）的数据状态）是否改变  不包括需要单独走事件的数据的改变状态 
        /// 
        /// 具体到本程序：网格选项卡中的除了 等值线 Contour 和 向量 Vector 外的数据的更新状态
        /// </summary>
        /// <returns></returns>
        public bool IsDataChanged( )
        {
            if (this==null )
            {
                return false;
            }
            if (this._isShowTab == false)
            {
                return false;
            }

            if (this.IsNeedUpdateData == true)//不包括单独走事件更新的数据
            {
                return true;
            }
            else
            {
                return false;   
            }

            //throw new NotImplementedException();
        }

        #endregion









        #region 暂时不使用
        //public void ResetDOGrid3d(DOGrid3d grid)
        //{
        //    try
        //    {
        //        #region
        //        List<string> properties = new List<string>();
        //        if (this._isShowContour != grid.IsShowContour)
        //        {
        //            properties.Add(DisplayOptionChangedLabel.IsShowContour.ToString());
        //        }
        //        if (this._isShowVector != grid.IsShowVector)
        //        {
        //            properties.Add(DisplayOptionChangedLabel.IsShowVector.ToString());
        //        }
        //        if (properties.Count > 0)
        //        {
        //            this.AskDisplayOptionChanged(new DisplayOptionsChangedEventArgs(this, DisplayOptionsType.Grid3D, properties));
        //        }
        //        #endregion
        //    }
        //    catch
        //    {
        //    }
        //    ///等值线的详细设置改变，不通过字段传递
        //}

        //#region 事件模型
        //[field: NonSerialized]
        //public event EventHandler<DisplayOptionsChangedEventArgs> DisplayOptionsChanged;
        //public void AskDisplayOptionChanged(DisplayOptionsChangedEventArgs e)
        //{
        //    if (DisplayOptionsChanged != null)
        //    {
        //        DisplayOptionsChanged(this, e);

        //    }
        //}
        //#endregion

        #endregion


    }
}
